﻿<sdk:Page 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:tlk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
           xmlns:local="clr-namespace:CandyNx" 
           x:Class="Candy.JobManagerPage"
           mc:Ignorable="d"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="JobManager"
           DataContext="{Binding Source={StaticResource Locator}, Path=JobManager}"
    >
    <Grid x:Name="LayoutRoot">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Height="Auto" Width="Auto" Margin="0,3,0,0">
            <Grid.RowDefinitions  >
                <RowDefinition Height="0.922*"/>
                <RowDefinition Height="0.078*"/>
            </Grid.RowDefinitions>
            <sdk:TreeView x:Name="jobTree" SelectedItemChanged="OnJobSelected"   Grid.RowSpan="2" ItemsSource="{Binding Jobs}" >
                <sdk:TreeView.ItemTemplate>
                    <sdk:HierarchicalDataTemplate  ItemsSource="{Binding Jobs}">
                        <Grid Background="Transparent">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"  />
                                <ColumnDefinition  Width="*"/>
                            </Grid.ColumnDefinitions>
                            <tlk:ContextMenuService.ContextMenu>
                                <tlk:ContextMenu >
                                    <tlk:MenuItem Header="Delete" CommandParameter="{Binding Mode=OneWay}" Command="{Binding JobManager.DeleteJob, Mode=OneWay, Source={StaticResource Locator}}" />
                                </tlk:ContextMenu>
                            </tlk:ContextMenuService.ContextMenu>
                            <StackPanel Orientation="Horizontal" Margin="-4,0,4,0" >
                                <Image Visibility="{Binding Entity.Status, Converter={StaticResource JobStatusVisibilityConverter}, ConverterParameter=PENDING, FallbackValue=Collapsed}" ToolTipService.ToolTip="Scheduled" Source="Images/Icons/Hourglass.png" Stretch="None" />
                                <Image Visibility="{Binding Entity.Status, Converter={StaticResource JobStatusVisibilityConverter}, ConverterParameter=RUNNING, FallbackValue=Collapsed}" ToolTipService.ToolTip="Running" Source="Images/Icons/Gear.png" Stretch="None" />
                                <Image Visibility="{Binding Entity.Status, Converter={StaticResource JobStatusVisibilityConverter}, ConverterParameter=DONE, FallbackValue=Collapsed}" ToolTipService.ToolTip="Done" Source="Images/Icons/Done.png" Stretch="None" />
                                <Image Visibility="{Binding Entity.Status, Converter={StaticResource JobStatusVisibilityConverter}, ConverterParameter=ERROR, FallbackValue=Collapsed}" ToolTipService.ToolTip="Error" Source="Images/Icons/Warning Message.png" Stretch="None"  />
                            </StackPanel>
                            <TextBlock  Text="{Binding Path=Name}" Grid.Column="1" />
                        </Grid>
                    </sdk:HierarchicalDataTemplate>
                </sdk:TreeView.ItemTemplate>
            </sdk:TreeView>
        </Grid>
        <Grid Grid.Column="1" Margin="8,4,6,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <sdk:DataGrid  x:Name ="ResultDataGrid" SelectionChanged="OnJobSelectionChanged" AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected" ItemsSource="{Binding SelectedJob.Hits}" Grid.Row="1" >
                <sdk:DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,0,0" d:DesignWidth="625" Background="{StaticResource ControlBackground}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="18"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid Background="{x:Null}" Margin="0,0,0,0" Grid.Column="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <!--<Border HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="3" Background="#4D317BB9" BorderThickness="1,1,1,1" BorderBrush="#FF317BB9"/>-->
                                <TextBlock Text="Query  " Grid.Row="0"  Margin="22,0,6,0" FontFamily="Segoe UI Mono" FontSize="14"/>
                                <TextBlock Text="Pattern" Grid.Row="1" Margin="22,0,6,0"  FontFamily="Segoe UI Mono" FontSize="14"/>
                                <TextBlock Text="Match  " Grid.Row="2" Margin="22,0,6,0"  FontFamily="Segoe UI Mono" FontSize="14"/>
                                <TextBlock Text="{Binding Entity.QuerySeq}" Grid.Column="1" Grid.Row="0"  FontFamily="Segoe UI Mono" FontSize="14"/>
                                <TextBlock Text="{Binding Entity.Pattern}" Grid.Column="1" Grid.Row="1"  FontFamily="Segoe UI Mono" FontSize="14"/>
                                <TextBlock Text="{Binding Entity.MatchSeq}" Grid.Column="1" Grid.Row="2"  FontFamily="Segoe UI Mono" FontSize="14"/>
                            </Grid>
                            <Grid  Grid.Row="1" Margin="20,0,0,0" Grid.Column="1" Background="{StaticResource ControlBackgroundDark}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" MinWidth="114" />
                                    <ColumnDefinition Width="Auto" MinWidth="2"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Button Command="{Binding ImportGene}"  Content="{Binding ImportActionText}" Grid.Row="0"  Margin="0,2,6,2" />
                                <RadioButton Content="putative ortholog" Grid.Column="1" IsChecked="{Binding AsOrtholog, Mode=TwoWay}"  Margin="0,0,6,0" VerticalAlignment="Center" GroupName="entrytype"/>
                                <RadioButton Content="putative homolog" Grid.Column="2"  IsChecked="{Binding AsHomolog, Mode=TwoWay}" Margin="0,0,6,0" VerticalAlignment="Center" GroupName="entrytype"/>
                                <RadioButton Content="putative related" Grid.Column="3"  IsChecked="{Binding AsRelated, Mode=TwoWay}" Margin="0,0,6,0"  VerticalAlignment="Center" GroupName="entrytype"/>
                                <RadioButton Content="Just tag" Grid.Column="4"  IsChecked="{Binding JustTag, Mode=TwoWay}" Visibility="{Binding AllowJustTagging, Converter={StaticResource VisibilityConverter}}"  Margin="4,0,0,0" VerticalAlignment="Center" GroupName="entrytype" HorizontalAlignment="Left"/>
                            </Grid>
                            <Border HorizontalAlignment="Left" Margin="1,0,0,0" Width="15" Grid.RowSpan="2" Background="{Binding Heat, Mode=OneWay}"/>
                        </Grid>
                    </DataTemplate>
                </sdk:DataGrid.RowDetailsTemplate>
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid >
                                    <Border Background="{Binding Heat}" Margin="-2,-1,0,0" Width="15"/>
                                </Grid>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding StateImage}" ToolTipService.ToolTip="{Binding StatusText}"  Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Header="ID" Binding="{Binding Entity.GeneId}" />
                    <sdk:DataGridTextColumn  Header="Bait"  Binding="{Binding Entity.RequestGeneIdentifiere}" />
                    <sdk:DataGridTextColumn  Header="BaitSR"  Binding="{Binding Entity.RequestGeneSR}" />
                    <sdk:DataGridTextColumn Header="#GeneHits" Binding="{Binding Entity.GeneHitCounter}" />
                    <sdk:DataGridTextColumn Header="#Hits" Binding="{Binding Entity.HspsCounter}" />
                    <sdk:DataGridTextColumn Header="Description" Binding="{Binding Entity.Description}" />
                    <sdk:DataGridTextColumn Header="Length" Binding="{Binding Entity.Length}" />
                    <sdk:DataGridTextColumn Header="Score" Binding="{Binding Entity.Score}" />
                    <sdk:DataGridTextColumn Header="Expectation" Binding="{Binding Entity.Expectation}" />
                    <!--<data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Fill="{Binding Path=Heat}" Width="15"/>
                                <TextBlock Text="{Binding Result.expectation}" Style="{StaticResource DarkTextBlock}" />
                            </StackPanel>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>-->
                    <sdk:DataGridTextColumn Header="Probability" Binding="{Binding Entity.Probability}" />
                    <sdk:DataGridTextColumn Header="Identity" Binding="{Binding Entity.Identity}" />
                    <sdk:DataGridTextColumn Header="Positives" Binding="{Binding Entity.Positives}" />

                    <sdk:DataGridTemplateColumn Header="" IsReadOnly="True" MinWidth="3000">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock/>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
            <Button Content="Import All" HorizontalAlignment="Left" Margin="8,8,0,8" VerticalAlignment="Center" Visibility="{Binding SelectedJob.AllowImportAll, Converter={StaticResource VisibilityConverter}, Mode=OneWay, FallbackValue=Collapsed, TargetNullValue=Collapsed}" Command="{Binding SelectedJob.ImportAll, Mode=OneWay}"/>

        </Grid>

        <sdk:GridSplitter x:Name="Splitter" HorizontalAlignment="Left" Margin="0,0,3,0" Width="8" Grid.Row="1" Grid.Column="1" Grid.RowSpan="1"/>
        <!--Job info-->
        <Grid Margin="0,0,0,0"  Visibility="Collapsed" Grid.Row="1" Grid.Column="1" Background="#62000000" IsHitTestVisible="True" >
            <Grid.RowDefinitions>
                <RowDefinition Height="0.504*"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="0.496*"/>
            </Grid.RowDefinitions>
            <TextBlock Visibility="{Binding IsFirstLoad, Converter={StaticResource VisibilityConverter}}"  Margin="0,0,0,0" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Bottom" d:LayoutOverrides="Width" Height="42" HorizontalAlignment="Center"><Run Text="The first result processing of large gene families can take few minutes."/><LineBreak/><Run Text=" Please wait... "/></TextBlock>
            <TextBlock Height="Auto" Margin="0,0,0,0" VerticalAlignment="Top" Text="Loading..." TextAlignment="Center" TextWrapping="Wrap" d:LayoutOverrides="Width" Grid.Row="2" HorizontalAlignment="Center"/>
        </Grid>

    </Grid>
</sdk:Page>
